package com.dailyblue.project.smbms.alibaba.order.service.impl;

import com.dailyblue.project.smbms.alibaba.order.mapper.OrderMapper;
import com.dailyblue.project.smbms.alibaba.order.service.OrderService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.sql.SQLException;

@Service
public class OrderServiceImpl implements OrderService {
    @Resource
    private OrderMapper mapper;

    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = SQLException.class)
    public void saveOrder(String orderId, String aid, String order) {
        mapper.saveOrder(aid, orderId);
        String[] array = order.split(",");
        for (int i = 0; i < array.length; i++) {
            String s = array[i];
            String[] aa = s.split("=");
            String gid = aa[0];
            String num = aa[1];
            mapper.saveOrderDetails(orderId, gid, num);
        }
    }
}
